package com.lc.pianostudent.conn;

import com.lc.pianostudent.bean.AnswerResultBean;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;

/**
 * Created by Administrator on 2018/2/22.
 */
@HttpInlet(Conn.BUSI)
public class PostAnswerBusi extends BaseAsyPost {

    public String json,user_id,type,teacherid;
    public PostAnswerBusi(AsyCallBack asyCallBack) {
        super(asyCallBack);
    }

    @Override
    protected PostAnswerBusiInfo parser(JSONObject object) throws Exception {
        if (object.optString("code").equals("200")) {

            PostAnswerBusiInfo info = new PostAnswerBusiInfo();

            info.code = object.optString("code");
            info.yes = object.optString("yes");
            info.wrong = object.optString("wrong");
            info.history = object.optString("history");
            JSONArray array = object.optJSONArray("data");

            if(array != null || array.length() != 0){
                for(int i = 0;i<array.length();i++){
                    JSONObject jsonObject = array.optJSONObject(i);
                    AnswerResultBean answerResultBean = new AnswerResultBean();
                    answerResultBean.setId(jsonObject.optString("id"));
                    answerResultBean.setContent(jsonObject.optString("content"));
                    info.answerResultList.add(answerResultBean);
                }
            }
            TOAST = object.optString("message");
            return info;

        } else {

            TOAST = object.optString("message");

        }

        return null;
    }

    public static class PostAnswerBusiInfo {

        public String code,yes,wrong,history;

        public ArrayList<AnswerResultBean> answerResultList = new ArrayList<>();

    }

}
